<?php

/*

  Treasure	$5

  Worth $2
  When you shuffle, you may put this anywhere in your deck.

 */

class Stash extends Card implements iTreasure, iKingdom, iPromotion {

    public function __construct() {
        parent::__construct("Stash", 5);
        $this->value = new Price(2);
        $this->undoPlay = true;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Worth $2",
            "When you shuffle, you may put this anywhere in your deck.");
    }

    public function setDiscardDeck(Game $game, $name) {
        $oldPhase = $game->getPhase($name);

        $discard_deck = $game->getDiscardDeck($name);
        $stashes = array();
        $other_cards = array();
        foreach ($discard_deck as $card) {
            if ($card instanceof Stash) {
                $stashes[] = $card;
            } else {
                $other_cards [] = $card;
            }
        }

        if (sizeof($stashes) > 0) {
            $options = array();
            $k = 0;
            for ($i = 0; $i < sizeof($stashes); $i+=1) {
                $options[] = $stashes[$i];
                $k+=1;
            }

            for ($i = 0; $i < sizeof($discard_deck) - sizeof($stashes); $i+=1) {
                $options[] = new Option($k, "Card");
                $k+=1;
            }

            $output = MySocket::GetUserReply($game, Input_Reorder, $options, -1, -1, null, "Choose where to put Stash cards in deck", $name);
            $new_discard = array();
            foreach ($output as $ans) {
                if ($ans == "Stash") {
                    $new_discard[] = array_pop($stashes);
                } else {
                    $new_discard[] = array_pop($other_cards);
                }
            }
            $game->setPhase($oldPhase);
            return $new_discard;
        } else {
            $game->setPhase($oldPhase);
            return $discard_deck;
        }
    }

    public function autoPlayNum(Game $game) {
        return 5;
    }

    public function play(Game $game, $isRealCard) {
        
    }

}

?>